package views;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import business.interfaces.ICalendarioClase;
import data.entities.CalendarioClase;



@SuppressWarnings("serial")
public class ClasesTableModel extends AbstractTableModel {

	private static final int DIA_SEMANA = 0;
	private static final int HORA = 1;
	private static final int CUPO = 2;

	
	private List<ICalendarioClase> clases;

	final static String[] columnNames = { "Dia", "Hora", "Cupo"};

	boolean isEditable = false;

	public ClasesTableModel(List<ICalendarioClase> clases) {
		this.clases = clases;
	}

	public String getColumnName(int col) {
		return columnNames[col];
	}

	public int getRowCount() {
		return clases.size();
	}

	public int getColumnCount() {
		return columnNames.length;
	}

	public Object getValueAt(int row, int col) {
		Object result = null;
		CalendarioClase calendarioClase = (CalendarioClase) (clases
				.get(row));
		switch (col) {
		case DIA_SEMANA:
			result = getDayToString(calendarioClase.getDia());
			break;
		case HORA:
			result = calendarioClase.getHora();
			break;
		case CUPO:
			result = calendarioClase.getCupo();
			break;
		}
		return result;

	}
	
	private String getDayToString(Integer day){
		String result = "";
		switch(day){
			case 1:
				result = "Lunes";
			break;
			case 2:
				result = "Martes";
			break;
			case 3:
				result = "Miercoles";
			break;
			case 4:
				result = "Jueves";
			break;
			case 5:
				result = "Viernes";
			break;
			case 6:
				result = "Sabado";
			break;
			case 7:
				result = "Domingo";
			break;
		}
		return result;
	}

	public ICalendarioClase getUbicacionAtRow(int r) {
		ICalendarioClase result = null;
		try {
			result = clases.get(r);
		} catch (IndexOutOfBoundsException e) {
			System.out.println("No has elegido ninguna clase.");
		}
		
		return result;
	}

	public boolean isCellEditable(int row, int col) {
		return isEditable;
	}

	public void setEditable(boolean isEditable) {
		this.isEditable = isEditable;
	}

	public void setValueAt(Object value, int row, int col) {
	}
}
